﻿using System.Data;
using smp.QueryDb.Structure;

namespace smp.QueryDb.Executing
{
    public interface IInsertValue
    {
        Insert To(object value);
    }

    internal class InsertValue : IInsertValue
    {
        private readonly Insert _insert;
        private readonly DbType _dataType;
        private object _value;
        
        internal InsertValue(Insert insert, Column column)
        {
            _insert = insert;
            _dataType = column.DataType;
        }

        #region Implementation of IInsertValue

        public Insert To(object value)
        {
            _value = value;
            _insert.AddSetParameter(this);
            return _insert;
        }

        #endregion

        internal IParameter CreateParameter(string name)
        {
            return new Parameter(name, _dataType, _value);
        }
    }
}
